<!--
 * @Author: 亚亚
-->
<!--
 * @Author: 亚亚
-->
<!--
 * @Author: 亚亚
-->
<!--
 * @Author: 亚亚
-->
<!--
 * @Author: 亚亚
-->
<template>
  <el-tree
    ref="treeRef"
    v-bind="$attrs"
    v-model="currentVal"
    :style="props.style"
    :props="props.props"
  />
</template> 

<script lang="ts" setup>
import { props as treeProps } from './index'
const props = defineProps(treeProps)
const emit = defineEmits(['update:modelValue'])
const currentVal = ref(props.modelValue)

//@ts-expect-error
const treeRef = ref<InstanceType<typeof ElTree>>()
  
//监听父组件的值
watch(() => props.modelValue, () => {
  currentVal.value = props.modelValue
  if(!treeRef?.value) return
  treeRef.value.setCheckedKeys(currentVal.value)
},{
  deep: true
})
// 通过emit将值传递给父组件
emit("update:modelValue", currentVal)
</script>
